<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>管理员登陆</title>
    <th:block th:replace="layout :: resource"></th:block>
</head>
<body class="zjgl-layout-page">
<div class="login layui-anim layui-anim-up">
    <div class="message">超市库存管理系统</div>
    <div id="darkbannerwrap"></div>
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">账&nbsp;&nbsp;&nbsp;&nbsp;号</label>
            <div class="layui-input-inline">
                <input type="text" name="username" required lay-verify="required" placeholder="管理员账号"
                       lay-reqText="该项不能为空！" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                       lay-reqText="用户名不能为空！" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux" id="tip"></div>
        </div>
        <div class="layui-form-item" style="margin-top: 50px">
            <div style="margin-left: 65px">
                <button class="layui-btn layui-btn-warm" lay-submit lay-filter="formDemo" style="width: 200px">登录
                </button>
            </div>
        </div>
    </form>
</div>


<script>
    pageObj = {
        loginUrl: "/admin/api/login",
        goodsUrl: "/goods/home"
    }
    layui.use('form', function () {
        layui.$('form [lay-verify]').attr('lay-verType', 'tips');
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var formData = data.field;
            $.ajax({
                type: 'POST',
                contentType: 'application/json',
                dateType: "json",
                url: pageObj.loginUrl,
                async: false,
                data: JSON.stringify(formData),
                success: function (result) {
                    if (result.code === 0) {
                        layer.msg("登录成功");
                        setTimeout(function () {
                            window.location.href = pageObj.goodsUrl;
                        }, 500);
                    } else if (result.code === 500) {
                        $("#tip").html("<div style='width: 200px;border: 1px #ff0000;margin-left: 105px;margin-top: 20px'><span  style='color: red;'>用户名或密码错误！</span></div>");
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>